home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-25 | 29.0 KB | 1,062 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: DrawPart.cpp
- // Release Version: $ ODF 1 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k"
- #endif
-
- #ifndef BINDING_K
- #include "Binding.k"
- #endif
-
- #ifndef CONSTANT_H
- #include "Constant.h"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k"
- #endif
-
- #ifndef DRAWCONT_H
- #include "DrawCont.h"
- #endif
-
- #ifndef DRAWFRM_H
- #include "DrawFrm.h"
- #endif
-
- #ifndef DRAWPRXY_H
- #include "DrawPrxy.h"
- #endif
-
- #ifndef BASESHP_H
- #include "BaseShp.h"
- #endif
-
- #ifndef BOUNDSHP_H
- #include "BoundShp.h"
- #endif
-
- #ifndef LINESHP_H
- #include "LineShp.h"
- #endif
-
- #ifndef OVALSHP_H
- #include "OvalShp.h"
- #endif
-
- #ifndef RECTSHP_H
- #include "RectShp.h"
- #endif
-
- #ifndef RRECTSHP_H
- #include "RRectShp.h"
- #endif
-
- #ifndef TEXTSHP_H
- #include "TextShp.h"
- #endif
-
- #ifndef DRAWSEL_H
- #include "DrawSel.h"
- #endif
-
- #ifndef DRAWLINK_H
- #include "DrawLink.h"
- #endif
-
- #ifndef TOOLFRM_H
- #include "ToolFrm.h"
- #endif
-
- #ifndef PALFRAME_H
- #include "PalFrame.h"
- #endif
-
- #ifndef PATFRAME_H
- #include "PatFrame.h"
- #endif
-
- #ifndef DRAWCMDS_H
- #include "DrawCmds.h"
- #endif
-
- #ifndef DRAWCLIP_H
- #include "DrawClip.h"
- #endif
-
- #ifndef GROUPCMD_H
- #include "GroupCmd.h"
- #endif
-
- #ifndef SOM_ODFExamples_ODFDrawEmbeddedFramesIterator_xh
- #include "SOMIter.xh"
- #endif
-
- //#ifndef ALGNOBFR_H
- //#include "AlgnObFr.h"
- //#endif
-
- // ----- Part Layer -----
-
- #ifndef FWABOUT_H
- #include "FWAbout.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWSCLBAR_H
- #include "FWSclBar.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWAPLEVT_H
- #include "FWAplEvt.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWWINDOW_H
- #include "FWWindow.h"
- #endif
-
- #ifndef FWFLOWIN_H
- #include "FWFloWin.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWALERT_H
- #include "FWAlert.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef SLMixOS_H
- #include "SLMixOS.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWSTRING_H
- #include "FWString.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODInfo_xh
- #include <Info.xh>
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdraw
- #endif
-
- FW_DEFINE_CLASS_M2(CDrawPart, FW_CEmbeddingPart, FW_MEmbeddingPartScriptable)
- FW_DEFINE_AUTO(CDrawPart)
-
- //========================================================================================
- // class CDrawPart
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::CDrawPart
- //----------------------------------------------------------------------------------------
-
- CDrawPart::CDrawPart(ODPart* odPart) :
- FW_CEmbeddingPart(odPart, FW_gInstance, kPartInfoID),
- FW_MEmbeddingPartScriptable(),
- fNbEmbedded(0),
- fPartContent(NULL),
- fCurrentPenSize(FW_kFixedPos1),
- fRenderVerb(kFillFrame),
- fPaletteWindow(NULL),
- fPatternWindow(NULL),
- fToolsWindow(NULL),
- fToolFrame(NULL),
- fPaletteFrame(NULL),
- fPatternFrame(NULL),
- fPalettePresentation(NULL),
- fPatternPresentation(NULL),
- fToolPresentation(NULL),
- fMainPresentation(NULL),
- fAlignObjectsPresentation(NULL),
- fTool(kSelectTool),
- fFillColor(FW_kRGBWhite),
- fFrameColor(FW_kRGBBlack),
- fAutoGrid(TRUE),
- fUnit(cInchUnit),
- fArcUnit(cDegreesUnit),
- fPostCreated(FALSE)
- {
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::~CDrawPart
- //----------------------------------------------------------------------------------------
-
- CDrawPart::~CDrawPart()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::ReleaseAll
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::ReleaseAll(Environment *ev)
- {
- FW_CEmbeddingPart::ReleaseAll(ev);
-
- delete fPaletteWindow;
- delete fPatternWindow;
- delete fToolsWindow;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::Initialize
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::Initialize(Environment *ev)
- {
- // ----- Call Inherited Initialize -----
- FW_CEmbeddingPart::Initialize(ev);
-
- fDrawingSize.Set(FW_IntToFixed(kDrawingSizeX), FW_IntToFixed(kDrawingSizeY));
-
- #ifdef FW_BUILD_WIN
- // [HLX] Temporary embed menu for windows
- WinAddEmbedMenu(ev, GetMenuBar(ev));
- #endif
-
- // ----- Initialize the menu bar -----
- FW_DO_NOT_DEAD_STRIP(FW_CToggleItem);
- FW_DO_NOT_DEAD_STRIP(FW_CSubMenuItem);
- GetMenuBar(ev)->InitializeFromResource(ev, kMenuBar);
-
- // ----- Tokenize -----
- fDrawSelection = FW_NEW(CDrawSelection, (ev, this)); // Attention I don't own the selection the presentation will
-
- fToolPresentation = RegisterPresentation(ev, kToolPresentation, FALSE);
- fPalettePresentation = RegisterPresentation(ev, kPalettePresentation, FALSE);
- fPatternPresentation = RegisterPresentation(ev, kPatternPresentation, FALSE);
- fMainPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, fDrawSelection);
- fAlignObjectsPresentation = RegisterPresentation(ev, kAlignObjectsPresentation, FALSE);
-
- InitializePalettes(ev);
-
- // ----- Pattern Table -----
- fPatternTable[0] = FW_kBlackPat;
- fPatternTable[1] = FW_kWhitePat;
- fPatternTable[2] = FW_kGrayPat;
- fPatternTable[3] = FW_kLightGrayPat;
- fPatternTable[4] = FW_kDarkGrayPat;
- fPatternTable[5] = FW_kHorizontalPat;
- fPatternTable[6] = FW_kVerticalPat;
- fPatternTable[7] = FW_kFDiagonalPat;
- fPatternTable[8] = FW_kBDiagonalPat;
- fPatternTable[9] = FW_kCrossPat;
- fPatternTable[10] = FW_kDiagCrossPat;
- fPatternTable[11] = FW_kAntPat;
-
- fFillPatIndex = 0;
- fFramePatIndex = 0;
- }
-
- //------------------------------------------------------------------------------
- // CDrawPart::InitializePalettes
- //------------------------------------------------------------------------------
-
- void CDrawPart::InitializePalettes(Environment *ev)
- {
- FW_CPoint position(FW_IntToFixed(100), FW_IntToFixed(100));
- fPatternWindow = new FW_CFloatingWindow(ev,
- this,
- fPatternPresentation,
- FW_CString32(""),
- FW_kZeroPoint,
- position,
- TRUE);
-
- fPaletteWindow = new FW_CFloatingWindow(ev,
- this,
- fPalettePresentation,
- FW_CString32(""),
- FW_kZeroPoint,
- position,
- TRUE);
-
- FW_CPoint windowSize(FW_IntToFixed(kToolsWindowWidth), FW_IntToFixed(kToolsWindowHeight));
- fToolsWindow = new FW_CFloatingWindow(ev,
- this,
- fToolPresentation,
- FW_CString32(""),
- windowSize,
- position,
- TRUE);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::NewDocumentWindow
- //----------------------------------------------------------------------------------------
-
- FW_CWindow* CDrawPart::NewDocumentWindow(Environment* ev)
- {
- FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
-
- // ----- Add the rulers -----
- sbSize.x += kRulerWidth;
- sbSize.y += kRulerWidth;
-
- FW_CPoint drawingSize(fDrawingSize.x + sbSize.x, fDrawingSize.y + sbSize.y);
-
- FW_CRect screenBounds;
- ::FW_GetMainScreenBounds(screenBounds);
- screenBounds.Inset(FW_IntToFixed(3), FW_IntToFixed(3));
-
- return new FW_CWindow(ev,
- this,
- FW_CPart::gViewAsFrameToken,
- fMainPresentation,
- drawingSize,
- screenBounds.TopLeft(),
- FW_kDocumentWindow);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::NewPartContent
- //----------------------------------------------------------------------------------------
-
- FW_CContent* CDrawPart::NewPartContent(Environment* ev)
- {
- fPartContent = FW_NEW(CDrawPartContent, (ev, this));
- return fPartContent;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::InternalizeAnnotations
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::InternalizeAnnotations(Environment *ev, ODStorageUnit* storageUnit)
- {
- // ----- Read general information -----
- if (storageUnit->Exists(ev, kContentAnnotationProp, (ODValueType)kContentAnnotationValue, 0))
- {
- FW_PStorageUnitSink suSink(ev, storageUnit, kContentAnnotationProp, kContentAnnotationValue);
- FW_PBufferedSink sink(ev, suSink);
- FW_CReadableStream stream(sink);
- stream >> fCurrentPenSize;
- stream >> fRenderVerb;
- stream >> fAutoGrid;
- }
-
- // ----- Now we have read everything in we can call the facet clipper -----
- CDrawFacetClipper facetClipper(ev, this);
- facetClipper.Clip(ev, fMainPresentation, NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::ExternalizeAnnotations
- //----------------------------------------------------------------------------------------
- void CDrawPart::ExternalizeAnnotations(Environment* ev, ODStorageUnit* storageUnit)
- {
- // ----- Write general information -----
- // FW_SUAddPropValue correctly test if the property and value exist before
- // trying to create them
- FW_SUAddPropValue(ev, storageUnit, kContentAnnotationProp, kContentAnnotationValue);
-
- FW_PStorageUnitSink suSink(ev, storageUnit, kContentAnnotationProp, kContentAnnotationValue);
- FW_CWritableStream stream(suSink);
- stream << fCurrentPenSize;
- stream << fRenderVerb;
- stream << fAutoGrid;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::NewLinkManager
- //----------------------------------------------------------------------------------------
- FW_CLinkManager* CDrawPart::NewLinkManager(Environment *ev)
- {
- CDrawLinkManager* linkMgr = FW_NEW(CDrawLinkManager, (ev, this));
- return linkMgr;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::AddShapeToPart
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::AddShapeToPart(Environment* ev, CBaseShape* shape)
- {
- fPartContent->AddShape(ev, shape);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::RemoveShapeFromPart
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::RemoveShapeFromPart(Environment* ev, CBaseShape* shape)
- {
- fPartContent->RemoveShape(ev, shape);
- shape->Removed(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::DoMenu
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
- {
- FW_CString32 name("ODFDraw");
- FW_CString32 sorry("Sorry, not yet implemented!");
-
- FW_Boolean result = TRUE;
- ODCommandID commandID = theMenuEvent.GetCommandID(ev);
-
- if (cPen1 <= commandID && commandID <= cPen5)
- {
- int temp = cPen1;
- FW_Fixed penSize = FW_IntToFixed(commandID - temp + 1);
- if (!fDrawSelection->IsEmpty(ev))
- {
- CChangePenSizeCommand* cmd = FW_NEW(CChangePenSizeCommand, (ev, this, this->GetLastActiveFrame(ev), fDrawSelection, penSize));
- cmd->Execute(ev);
- }
- else
- fCurrentPenSize = penSize;
- }
- else
- {
- switch (commandID)
- {
- case kODCommandAbout:
- ::FW_About(ev, this, kAbout);
- break;
-
- case cHideShowPattern:
- fPatternWindow->ShowHide(ev, !fPatternWindow->IsShown(ev));
- break;
-
- case cHideShowPalette:
- fPaletteWindow->ShowHide(ev, !fPaletteWindow->IsShown(ev));
- break;
-
- case cHideShowTools:
- fToolsWindow->ShowHide(ev, !fToolsWindow->IsShown(ev));
- break;
-
- case cMoveForward:
- if (fPartContent->MoveForward(ev))
- {
- UpdateAfterMove(ev);
- this->Changed(ev);
- }
- break;
- case cMoveToFront:
- fPartContent->MoveToFront(ev);
- UpdateAfterMove(ev);
- this->Changed(ev);
- break;
- case cMoveBackward:
- if (fPartContent->MoveBackward(ev))
- {
- UpdateAfterMove(ev);
- this->Changed(ev);
- }
- break;
- case cMoveToBack:
- fPartContent->MoveToBack(ev);
- UpdateAfterMove(ev);
- this->Changed(ev);
- break;
-
- case cAutoGrid:
- fAutoGrid = !fAutoGrid;
- break;
-
- case cAlignObjects:
- #ifdef FW_DIALOGS_WIP
- LaunchDialog(ev, fAlignObjectsPresentation, kModalDialog,
- FW_CPoint(ff(100), ff(100)), FW_CPoint(ff(360), ff(220)));
- #endif
- // break;
-
- case cGroup:
- {
- CGroupShapesCommand* cmd = FW_NEW(CGroupShapesCommand, (ev, this->GetLastActiveFrame(ev), fDrawSelection));
- cmd->Execute(ev);
- }
- break;
- case cUngroup:
- {
- CUngroupShapesCommand* cmd = FW_NEW(CUngroupShapesCommand, (ev, this->GetLastActiveFrame(ev), fDrawSelection));
- cmd->Execute(ev);
- }
- break;
-
- case cAlignToGrid:
- case cRotate:
- case cFlipH:
- case cFlipV:
- case cLock:
- case cUnlock:
- case cScaleSelection:
- case cRoundCorners:
- FW_NoteAlert(name, sorry);
- break;
-
- case cInchUnit:
- case cCmUnit:
- case cPixelUnit:
- case cPicaUnit:
- fUnit = commandID;
- FW_NoteAlert(name, sorry);
- break;
-
- case cDegreesUnit:
- case cRadiansUnit:
- fArcUnit = commandID;
- FW_NoteAlert(name, sorry);
- break;
-
- default:
- result = FALSE;
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::SetTool
- //----------------------------------------------------------------------------------------
- void CDrawPart::SetTool(Environment* ev, unsigned short newTool)
- {
- if (fTool != newTool)
- {
- if (fTool == kSelectTool && !fDrawSelection->IsEmpty(ev))
- fDrawSelection->CloseSelection(ev);
-
- CheckTool(ev, fTool, newTool);
- fTool = newTool;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::SetRenderVerb
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::SetRenderVerb(Environment* ev, unsigned short renderVerb)
- {
- if (fRenderVerb != renderVerb)
- {
- if (!fDrawSelection->IsEmpty(ev))
- {
- CChangeRenderVerbCommand* cmd = FW_NEW(CChangeRenderVerbCommand,
- (ev, this, this->GetLastActiveFrame(ev), fDrawSelection, renderVerb));
- cmd->Execute(ev);
- }
-
- unsigned short oldRenderVerb = fRenderVerb;
- fRenderVerb = renderVerb;
- CheckRenderVerb(ev, oldRenderVerb, fRenderVerb);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::NewFrame
- //----------------------------------------------------------------------------------------
-
- FW_CFrame* CDrawPart::NewFrame(Environment* ev,
- ODFrame* odFrame,
- FW_CPresentation* presentation,
- FW_Boolean fromStorage)
- {
- if (presentation == fPalettePresentation)
- {
- if (fPaletteFrame)
- return fPaletteFrame;
- else
- return (fPaletteFrame = FW_NEW(CPaletteFrame, (ev, odFrame, presentation, this)));
- }
- else if (presentation == fPatternPresentation)
- {
- if (fPatternFrame)
- return fPatternFrame;
- else
- return (fPatternFrame = FW_NEW(CPatternFrame, (ev, odFrame, presentation, this)));
- }
- else if (presentation == fToolPresentation)
- {
- if (fToolFrame)
- return fToolFrame;
- else
- return (fToolFrame = FW_NEW(CToolFrame, (ev, odFrame, presentation, this)));
- }
- // else if (presentation == fAlignObjectsPresentation)
- // {
- // return FW_NEW(CAlignObjectsFrame, (ev, odFrame, this));
- // }
-
- // Create CDrawFrame from resources, using a different set of resources depending on
- // whether this frame is embedded or not to avoid creating a grow-box and scroll-bars.
- // NOTE: Another solution is to use only 1 set of resources and remove the grow-box
- // and scroll-bars in HandlePostCreateViewFromStream(). See the Container sample.
- FW_ResourceId id = odFrame->IsRoot(ev) ? kDrawView : kDrawViewNotRoot;
-
- return FW_NEW(CDrawFrame, (ev, odFrame, presentation, this, id));
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
- {
- if (!hasMenuFocus)
- return FALSE;
-
- ODCommandID command;
- FW_Boolean hasSelection = fDrawSelection->Count() > 0;
-
- // ----- Edit Menu -----
- menuBar->EnableCommand(ev, kODCommandSelectAll, fPartContent->CountShapes() > 0);
-
- // ----- PenSize Menu -----
- FW_Fixed penSize = fCurrentPenSize;
- if (fDrawSelection->Count() >= 1)
- {
- if (!fDrawSelection->GetSelectionPenSize(ev, penSize))
- {
- penSize = FW_kFixed0;
- }
- }
- command = FW_FixedToInt(penSize) + cPen1 - 1;
-
- for (ODCommandID p = cPen1; p <= cPen5; p++)
- menuBar->EnableAndCheckCommand(ev, p, TRUE, p == command);
-
- FW_Boolean readWrite = !IsReadOnly(ev);
-
- // ----- Arrange Menu -----
- menuBar->EnableCommand(ev, cMoveForward, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cMoveToFront, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cMoveBackward, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cMoveToBack, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cAlignToGrid, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cAlignObjects, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cRotate, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cFlipH, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cFlipV, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cGroup, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cUngroup, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cLock, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cUnlock, readWrite && hasSelection);
-
- // ----- Options Menu -----
- menuBar->EnableAndToggleCommand(ev, cAutoGrid, TRUE, !fAutoGrid);
- menuBar->EnableCommand(ev, cScaleSelection, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cRoundCorners, TRUE);
-
- // ----- Units Menu -----
- menuBar->EnableAndCheckCommand(ev, cInchUnit, TRUE, fUnit == cInchUnit);
- menuBar->EnableAndCheckCommand(ev, cCmUnit, TRUE, fUnit == cCmUnit);
- menuBar->EnableAndCheckCommand(ev, cPixelUnit, TRUE, fUnit == cPixelUnit);
- menuBar->EnableAndCheckCommand(ev, cPicaUnit, TRUE, fUnit == cPicaUnit);
- menuBar->EnableAndCheckCommand(ev, cDegreesUnit, TRUE, fArcUnit == cDegreesUnit);
- menuBar->EnableAndCheckCommand(ev, cRadiansUnit, TRUE, fArcUnit == cRadiansUnit);
-
- // ----- Window Menu -----
- menuBar->EnableAndToggleCommand(ev, cHideShowTools, TRUE, fToolsWindow == NULL || !fToolsWindow->IsShown(ev));
- menuBar->EnableAndToggleCommand(ev, cHideShowPalette, TRUE, fPaletteWindow == NULL || !fPaletteWindow->IsShown(ev));
- menuBar->EnableAndToggleCommand(ev, cHideShowPattern, TRUE, fPatternWindow == NULL || !fPatternWindow->IsShown(ev));
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::CheckTool
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::CheckTool(Environment* ev, unsigned short oldTool, unsigned short newTool)
- {
- if (fToolFrame != NULL)
- fToolFrame->CheckTool(ev, oldTool, newTool);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::CheckRenderVerb
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::CheckRenderVerb(Environment* ev, unsigned short oldRenderVerb, unsigned short newRenderVerb)
- {
- if (fToolFrame != NULL)
- fToolFrame->CheckRenderVerb(ev, oldRenderVerb, newRenderVerb);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::UpdateAfterMove
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::UpdateAfterMove(Environment* ev)
- {
- CDrawFacetClipper facetClipper(ev, this);
- facetClipper.Clip(ev, fMainPresentation, fDrawSelection->GetUpdateShape());
-
- fMainPresentation->Invalidate(ev, fDrawSelection->GetUpdateShape());
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::UpdateAllToolFacets
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::UpdateAllToolFacets(Environment *ev)
- {
- if (fToolFrame != NULL)
- fToolFrame->UpdateColors(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::SetFillColor
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::SetFillColor(Environment *ev, const FW_CColor& color)
- {
- if (fDrawSelection->IsEmpty(ev))
- {
- fFillColor = color;
- UpdateAllToolFacets(ev);
- }
- else if (!fDrawSelection->IsOKtoEdit(ev))
- {
- FW_Beep();
- }
- else
- {
- CChangeColorCommand* cmd = FW_NEW(CChangeColorCommand,
- (ev, cChangeFillColor, this, this->GetLastActiveFrame(ev), fDrawSelection, color));
- cmd->Execute(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::SetFrameColor
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::SetFrameColor(Environment *ev, const FW_CColor& color)
- {
- if (fDrawSelection->IsEmpty(ev))
- {
- fFrameColor = color;
- UpdateAllToolFacets(ev);
- }
- else if (!fDrawSelection->IsOKtoEdit(ev))
- {
- FW_Beep();
- }
- else
- {
- CChangeColorCommand* cmd = FW_NEW(CChangeColorCommand,
- (ev, cChangeFrameColor, this, this->GetLastActiveFrame(ev), fDrawSelection, color));
- cmd->Execute(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::SetFillPattern
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::SetFillPattern(Environment *ev, short newFillPatIndex)
- {
- if (fDrawSelection->IsEmpty(ev))
- {
- fFillPatIndex = newFillPatIndex;
- UpdateAllToolFacets(ev);
- }
- else if (!fDrawSelection->IsOKtoEdit(ev))
- {
- FW_Beep();
- }
- else
- {
- FW_CPattern pattern = GetPattern(newFillPatIndex).Copy();
- CChangePatternCommand* cmd = FW_NEW(CChangePatternCommand,
- (ev, cChangeFillPattern, this, this->GetLastActiveFrame(ev), fDrawSelection, pattern));
- cmd->Execute(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::SetFramePattern
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::SetFramePattern(Environment *ev, short newFramePatIndex)
- {
- if (fDrawSelection->IsEmpty(ev))
- {
- fFramePatIndex = newFramePatIndex;
- UpdateAllToolFacets(ev);
- }
- else if (!fDrawSelection->IsOKtoEdit(ev))
- {
- FW_Beep();
- }
- else
- {
- FW_CPattern pattern = GetPattern(newFramePatIndex).Copy();
- CChangePatternCommand* cmd = FW_NEW(CChangePatternCommand,
- (ev, cChangeFramePattern, this, this->GetLastActiveFrame(ev), fDrawSelection, pattern));
- cmd->Execute(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::WhichShape
- //----------------------------------------------------------------------------------------
-
- CBaseShape* CDrawPart::WhichShape(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent, FW_Boolean hasToBeSelected) const
- {
- CDrawContentShapeIterator ite(fPartContent);
- for (CBaseShape* shape = ite.Last(); ite.IsNotComplete(); shape = ite.Previous())
- {
- FW_Boolean test = (!hasToBeSelected) || (hasToBeSelected && shape->IsSelectedShape());
- if (test && shape->HitTest(ev, gc, theMouseEvent))
- return shape;
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::FindShapeWithIndex
- //----------------------------------------------------------------------------------------
- CBaseShape* CDrawPart::FindShapeWithIndex(short extIndex)
- {
- // Search the shape list and return the shape with the specified externalization index
- CDrawContentShapeIterator ite(fPartContent);
- for (CBaseShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- if (shape->GetExternalizationIndex() == extIndex)
- return shape;
- }
-
- // extIndex not found!?
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::DoPostCreate
- //----------------------------------------------------------------------------------------
- void CDrawPart::DoPostCreate(Environment* ev)
- {
- // Perform "DoPostCreate"-type initialization.
- // In our case, we want to make sure that any subscribers that were just internalized
- // get registered for automatic updates.
-
- if (!fPostCreated) // do this only once!
- {
- CDrawLinkManager* linkMgr = (CDrawLinkManager*) this->GetLinkManager(ev);
- linkMgr->RegisterLinks(ev);
- fPostCreated = TRUE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::NewElementIterator
- //----------------------------------------------------------------------------------------
-
- FW_CElementIterator* CDrawPart::NewElementIterator(Environment* ev,
- FW_CPart* part,
- ODDescType elementType) const
- {
- FW_CElementIterator* iter;
-
- if (elementType == kShapeClass)
- iter = FW_NEW(CSemanticShapeElementIterator, (fPartContent));
- else
- iter = FW_MEmbeddingPartScriptable::NewElementIterator(ev, part, elementType);
-
- return iter;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::DoAECreateElement
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::DoAECreateElement(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- FW_CDesc propertyValues;
- unsigned short newShapeType = kRectShape;
-
- if (event.HasDataKey(keyAEPropData))
- event.GetDataByDesc(propertyValues, keyAEPropData, typeAERecord);
-
- if (propertyValues.HasDataKey(kShapeTypeProperty))
- {
- ODDescType shapeType;
- shapeType = propertyValues.GetEnumeratedType(kShapeTypeProperty);
-
- switch(shapeType)
- {
- case kLineShapeType:
- newShapeType = kLineShape;
- break;
-
- case kRectShapeType:
- newShapeType = kRectShape;
- break;
-
- case kOvalShapeType:
- newShapeType = kOvalShape;
- break;
-
- case kRRectShapeType:
- newShapeType = kRRectShape;
- break;
-
- case kTextShapeType:
- newShapeType = kTextShape;
- break;
-
- default:
- break;
- }
- propertyValues.DeleteListItem(kShapeTypeProperty);
- }
-
- CBaseShape* theShape = GetDrawContent()->NewShape(ev, newShapeType);
-
- FW_CColor color;
-
- theShape->SetFrameInk(FW_kNormalInk);
- theShape->SetFrameStyle(FW_kNormalStyle);
-
- theShape->ChangeRenderVerb(ev, this, GetRenderVerb());
- theShape->ChangePenSize(ev, this, GetPenSize());
-
- GetFrameColor(color);
- theShape->ChangeFrameColor(ev, this, color);
-
- GetFillColor(color);
- theShape->ChangeFillColor(ev, this, color);
-
- theShape->ChangeFramePattern(ev, this, GetFramePattern());
- theShape->ChangeFillPattern(ev, this, GetFillPattern());
-
- FW_CPoint topLeft(FW_IntToFixed(10), FW_IntToFixed(10));
- FW_CPoint botRight(FW_IntToFixed(82), FW_IntToFixed(82));
-
- theShape->SetShapeGeometry(topLeft, botRight);
-
- theShape->SetProperties(ev, part, propertyValues);
-
- CDrawShapeCommand* cmd = FW_NEW(CDrawShapeCommand,
- (ev, this, GetFrame(ev, part), fDrawSelection, theShape));
-
- cmd->Execute(ev);
-
- GetDrawContent()->RedrawShape(ev, theShape);
-
- FW_CDesc objectSpec;
-
- BuildObjectSpecifier(ev, part, GetFrame(ev, part), objectSpec, GetSpecifierForm());
- reply.PutDataByDesc(objectSpec, keyAEResult);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::EmbeddedFrameRemoved
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::EmbeddedFrameRemoved(Environment *ev, FW_MProxy* proxy)
- {
- CProxyShape* proxyShape = (CProxyShape*)proxy;
-
- FW_CRect updateBox;
- proxyShape->GetUpdateBox(updateBox);
-
- proxyShape->GetPresentation(ev)->Invalidate(ev, updateBox);
-
- RemoveShapeFromPart(ev, proxyShape);
-
- delete proxyShape;
- }
-